package com.system.demo.controller.paper;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.system.demo.entity.DTO.PaperSearchDTO;
import com.system.demo.service.PaperService;
import com.system.demo.tool.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/Paper/admin")
public class PaperAdminController {
    @Autowired
    private PaperService paperService;


    /**
     * 管理员查询学生论文相关信息
     *
     * @param paperSearchDTO
     * @param current
     * @param size
     * @return
     */
    @PostMapping("/search")
    @SaCheckPermission("PaperApprove")
    public ResponseResult<?> search(@RequestBody PaperSearchDTO paperSearchDTO, int current, int size) {
        System.out.println(paperSearchDTO);
        return paperService.PaperSearch(paperSearchDTO,current,size);
    }


    /**
     * 管理员认证学生论文申请
     *
     * @param applicationId
     * @param isPass
     * @return
     */
    @PostMapping("/applicate")
    @SaCheckPermission("PaperApprove")
    public ResponseResult<?> applicate(@RequestParam List<Integer> applicationId,@RequestParam String isPass){
        return paperService.PaperApplicate(applicationId,isPass);
    }


    /**
     * 管理员确定学生的论文等级
     * @param ids
     * @param level
     * @return
     */
    @PostMapping("/determine")
    @SaCheckPermission("PaperApprove")
    public ResponseResult<?> determine(@RequestParam List<Integer> ids, @RequestParam String isPass ,@RequestParam Integer level){
        return paperService.PaperDetermine(ids,isPass,level);
    }

    /**
     * 管理员导出excel表
     * @param paperSearchDTO
     * @return
     */
    @PostMapping("/export")
    @SaCheckPermission("PaperApprove")
    public void export(@RequestBody PaperSearchDTO paperSearchDTO, HttpServletResponse response) throws IOException {
        System.out.println(paperSearchDTO);
        paperService.PaperExport(paperSearchDTO, response);
    }


    /**
     * 最高级管理员修改认定结果
     * @param id 申请表id
     * @param isPass 是否通过
     * @param level 认定等级
     * @return
     */
    @PostMapping("/update")
    @SaCheckRole("ROLE_ADMIN")
    public ResponseResult<?> Update(@RequestParam Integer id, @RequestParam String isPass,@RequestParam Integer level){
        return paperService.LevelUpdate(id,isPass,level);
    }

    /**
     * 管理员批量下载证明材料
     * @param ids
     * @param response
     * @throws IOException
     */
    @PostMapping("/DownloadEvidence")
    @SaCheckPermission("PaperApprove")
    public void DownloadEvidence(@RequestParam List<Integer> ids, HttpServletResponse response) throws IOException {
        paperService.downloadEvidence(ids,response);
    }
}
